Unwrap(TResult) Method (Task(Task(TResult)))

Task Parallel System.Threading

Creates a proxy Task{TResult} that represents the asynchronous operation of a Task{Task{TResult}}.
Unwraps a Task that returns another Task.

Namespace:  System.Threading.Tasks
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function Unwrap(Of TResult) ( _
	task As Task(Of Task(Of TResult)) _
) As Task(Of TResult)
C#
public static Task<TResult> Unwrap<TResult>(
	Task<Task<TResult>> task
)

Parameters

task
Type: System.Threading.Tasks..::.Task<(Of <(Task<(Of <(TResult>)>)>)>)
The Task{Task{TResult}} to unwrap.

Type Parameters

TResult

Return Value

A Task{TResult} that represents the asynchronous operation of the provided Task{Task{TResult}}.

Remarks

It is often useful to be able to return a Task{TResult} from a Task{TResult}, where the inner Task{TResult} represents work done as part of the outer Task{TResult}. However, doing so results in a Task{Task{TResult}}, which, if not dealt with carefully, could produce unexpected behavior. Unwrap solves this problem by creating a proxy Task{TResult} that represents the entire asynchronous operation of such a Task{Task{TResult}}.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionThe exception that is thrown if the task argument is null.

See Also